Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 2a37496 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f52f0ae19
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| dispatcher.hooks.onDidRestore.register('media', async (_ctx, next) => { | ||
| this.captureBaseline(); |
There was a problem hiding this comment.
Preserve an undefined baseline after restoring media history
When an older session containing image or video parts is restored under a model that no longer supports that media type, this hook immediately records the current model as the baseline. Consequently, inject() sees previous equal to current and returns before reaching its unsupportedPriorMedia check, so the promised restore-time reminder is never emitted and the model is not told that earlier media was omitted or that it must not call Read for that type. Avoid capturing the baseline here, or retain enough pre-restore state to let the first post-restore injection inspect the restored history.
AGENTS.md reference: AGENTS.md:L191-L193
Useful? React with 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c582db9ae
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (previous.imageIn === current.imageIn && previous.videoIn === current.videoIn) { | ||
| return undefined; |
There was a problem hiding this comment.
Re-inject the capability reminder after compaction
After a vision-to-text-only model switch followed by full compaction, the reminder framework re-runs this provider with no lastDisclosure, but baseline still equals the current text-only capabilities, so this equality check suppresses the reminder. The compacted context has therefore lost the warning while the frozen Read schema still advertises image and video support, allowing the model to call Read on media it cannot consume. Treat a compaction rearm as requiring disclosure again, as the legacy merge reminder already does.
AGENTS.md reference: AGENTS.md:L111-L115
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81fa9472f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@moonshot-ai/agent-core-v2": minor | |||
There was a problem hiding this comment.
Mark the agent-core change as breaking
Consumers of @moonshot-ai/agent-core-v2 that still rely on ReadMediaFile or its region and full_resolution inputs lose that behavior after this release. The changeset explicitly removes them but classifies the package change as minor; mark it as breaking or preserve a compatibility path.
AGENTS.md reference: AGENTS.md:L90-L90
Useful? React with 👍 / 👎.
commit: |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Requirement or Bug
此前文件读取拆分为
Read(仅文本)与ReadMediaFile(图片与视频)两个工具,模型与用户需要区分两套重叠的文件读取入口,同时ReadMediaFile内置的region/full_resolution图片裁剪逻辑增加了工具参数复杂度与维护负担。本 PR 将图片与视频读取合并进Read并下线独立的ReadMediaFile工具及内置图片裁剪功能,同时保留存量旧会话的恢复与回放兼容,在恢复含旧版ReadMediaFile的会话时注入一次性迁移提醒,并在会话中途切换模型多模态能力时通过<system-reminder>提醒模型。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
将原先散落在
ReadMediaFileTool与动态工具注册器中的图片压缩、视频引用生成、模态能力校验收拢进ReadTool,让Read成为文本、图片、视频的唯一内置文件读取工具,并删除cropImageForModel(region/full_resolution参数与image_crop遥测)。由于Read现在常驻注册而不再随模型能力动态挂载/卸载,新增AgentMediaCapabilityReminderService在会话发生多模态能力切换时注入<system-reminder>;对于升级前写入的旧会话,AgentToolSelectService与mediaPolicy负责剔除已下线的ReadMediaFile声明、将旧版Readschema 刷新为当前定义、在首轮注入一次性legacy_read_media_merged<system-reminder>说明工具合并与裁剪参数移除,并保留残留调用拦截与历史记录兜底;Web/Desktop 与 TUI 则根据Read输出中的媒体标签将其渲染为媒体卡片与摘要,同时继续支持旧会话中的ReadMediaFile回放。结构图
flowchart TD Call["模型调用 Read(path)"] --> Detect{"detectFileType 嗅探类型"} Detect -- "UTF-8 / UTF-16 文本" --> TextPath["文本分页与编码读取"] Detect -- "图片 / 视频" --> CapCheck{"模型支持对应模态?"} CapCheck -- "否" --> CapErr["返回模态能力不足错误"] CapCheck -- "是" --> MediaPipe["校验参数与 100MB 上限 -> 压缩并写入 ISessionMediaStore -> 输出媒体标签与 ContentPart[]"] MediaPipe --> UI["app-core / TUI 渲染媒体卡片"] ModelSwitch["模型模态能力切换"] --> CapReminder["AgentMediaCapabilityReminderService 注入 media_capability 提醒"] LegacyResume["恢复旧会话"] --> ToolSelect["AgentToolSelectService 剔除死工具 + 刷新 Read schema + 首轮注入 legacy_read_media_merged 提醒 + 拦截误调用"]这样组织是因为文件访问权限、工作区边界、环境代际校验和
daemon-file://附件源本来就在ReadTool中维护,把媒体读取收拢到同一处后无需再跨动态注册器同步工具生命周期,也消除了按模型切换动态增删工具对上下文前缀稳定性的干扰。关键决策
Read常驻注册,模型在多模态与纯文本间切换时由AgentMediaCapabilityReminderService注入media_capability<system-reminder>ReadMediaFile一样按工具名隐藏历史Read调用Read同时承载文本和媒体读取,按工具名剥离会误删文本文件读取历史;底层协议的createMediaDegradeRecovery与mediaResolverService已会将不支持的媒体ContentPart降级为文本提示,配合 reminder 即可让模型清楚当前Read可读的模态范围。Readschema 处理ReadMediaFile,直接将旧版Read声明刷新为当前版本的新 schemaReadschema 并用提示词纠正tools[]中的ReadMediaFile本身已击穿全量前缀缓存;保留过时的Readschema 既无缓存收益,又会让工具描述与真实能力矛盾。直接刷新Readschema 更简洁,同时同版本 resume 字节完全不变。ReadMediaFile的旧会话首轮注入一次性legacy_read_media_merged<system-reminder>;compaction 丢弃后仅当历史仍保留ReadMediaFile调用时重注入Readschema + 误调ReadMediaFile时返回错误引导ReadMediaFile调用的旧会话时,原生 function calling 模型不会发出未在tools[]中声明的调用,误调拦截不会触发;模型反而因「历史里调过ReadMediaFile但当前工具列表里没有」而困惑,出现承诺下次继续用ReadMediaFile、误以为自己发出的Read调用是被系统改写等幻觉。一次性提醒直接解释工具下线原因,且不向新会话、同版本恢复或初始工具不含ReadMediaFile的旧会话注入噪音。Read图片压缩字节预算READ_IMAGE_BYTE_BUDGET = 256 KB(仍可通过KIMI_IMAGE_READ_BYTE_BUDGET调整)阅读指南
packages/agent-core-v2/src/agent/tools/os/read/readTool.ts(及read.ts、read.md):看Read如何分流文本与图片/视频读取、校验分页参数与模型模态能力、执行图片压缩并生成<image|video path="...">输出。packages/agent-core-v2/src/agent/media/image-compress.ts:看移除cropImageForModel后的图片压缩链路与更新后的外部裁剪提示语。packages/agent-core-v2/src/agent/media/mediaCapabilityReminderService.ts:看模型多模态能力发生切换或旧媒体会话恢复到受限模型时,如何按需注入media_capability<system-reminder>且避免常规首轮噪音。packages/agent-core-v2/src/agent/toolSelect/toolSelectService.ts与packages/agent-core-v2/src/agent/loop/mediaPolicy.ts:看旧会话恢复时如何过滤已下线的ReadMediaFile、刷新旧版Readschema、注入一次性legacy_read_media_merged迁移提醒(含 compaction 后的重注入条件)、拦截残留误调用并兼容历史ReadMediaFile消息对。packages/app-core/src/client/toolCalls.ts、apps/kimi-code/src/tui/components/messages/{read-group,tool-call}.ts、apps/kimi-code/src/tui/utils/transcript-items.ts与apps/kimi-code/src/tui/components/messages/tool-renderers/{media,chip,summary}.ts:看 Web/Desktop 与 TUI(含并行ReadGroupComponent与探索折叠摘要)如何把媒体类Read结果路由到媒体卡片/摘要渲染并保留历史ReadMediaFile展示。其余改动为机械清理与同步:删除
src/agent/tools/read-media-file/*与src/agent/media/{mediaTools,mediaToolsRegistrar,registerMediaTools}.ts、将createVideoUploader移至videoUpload.ts、从内置 profile 和默认放行策略中移除'ReadMediaFile'、重生成state-manifest.d.ts,以及同步更新测试与中英文文档。代码变更大纲
Behavior Changes and Affected Users
image_in/video_in时额外注册ReadMediaFile;Read遇到图片/视频报错并引导调用ReadMediaFileRead直接读取文本、图片与视频(上限100MB);不再注册独立的ReadMediaFile工具tools/exclude_tools)、权限审批规则、[tools]配置、外部 skill/prompt 或自定义脚本中显式指定ReadMediaFile的 TUI、print 模式、Desktop/Web、VS Code、ACP 与 SDK 用户ReadMediaFile工具的开关(统一改用Read,请维护者在本 PR 确认移除);恢复旧版持久化的会话时会自动过滤ReadMediaFile、将Read声明刷新为新版 schema、注入一次性迁移提醒,并对残留调用返回改用Read的明确引导region与full_resolution)及image_crop遥测ReadMediaFile支持传入region: { x, y, width, height }与full_resolution在工具内部裁剪大图局部并上报image_crop事件region/full_resolution参数与image_crop遥测;向媒体文件传入文本分页参数(line_offset/column_offset/n_lines/max_chars)会明确报错仅适用于文本文件image_crop遥测事件的看板Bash调用外部工具(如 Python PIL / ImageMagick)裁剪副本后再调用Read,或由用户通过环境变量KIMI_IMAGE_READ_BYTE_BUDGET/KIMI_IMAGE_MAX_EDGE_PX放宽预算image_in/video_in能力时的行为ReadMediaFile,并由hideReadMediaFile隐藏历史ReadMediaFile调用对Read保持注册;会话中途发生模态能力变化(或含历史媒体的旧会话在受限模型上恢复)时注入media_capability<system-reminder>;不支持对应模态时对媒体调用Read返回明确的能力缺失错误(如模型仅支持图片不支持视频时提示Only text and image files can be read.);旧会话中的ReadMediaFile历史消息仍由hideReadMediaFile隐藏/model或配置切换多模态与纯文本模型的 TUI、Desktop/Web、VS Code、ACP 用户image_in/video_in能力的模型即可继续读取对应媒体legacy_read_media_merged(AgentToolSelectService)ReadMediaFile的旧会话时仅静默剔除工具声明并刷新Readschema,不向模型解释历史ReadMediaFile调用的去向<system-reminder>:Tool "ReadMediaFile" has been retired and merged into "Read" in this version. Any earlier "ReadMediaFile" calls in this session are from an older version; do not call "ReadMediaFile" again. Call Read with { "path": "..." } to read text, image, and video files when the current model supports the modality. The "region" and "full_resolution" parameters are no longer supported.;compaction 丢弃该提醒后,仅当历史仍保留ReadMediaFile调用时重注入ReadMediaFile的会话的 TUI、print 模式、Desktop/Web、VS Code、ACP 与 SDK 用户(新会话、同版本恢复及初始工具不含ReadMediaFile的旧会话不注入)packages/agent-core-v2/src/agent/tools/read-media-file/read-media.mdimage_in/video_in能力的会话(含默认 profile、Plan 模式、Tower worker)提供ReadMediaFile工具描述、100MB 限制说明及region/full_resolution像素坐标指引read.md,裁剪坐标指引随裁剪功能下线移除read.md与ReadTool.readMedia运行时校验承接;裁剪能力已移除packages/agent-core-v2/src/agent/tools/os/read/read.md首句与附件段Read a UTF-8 or UTF-16 text file from the active environment's filesystem, or a kimi-file:// attachment of this session.,附件段含ReadMediaFile accepts the same reference for images and videos.(约束模型用ReadMediaFile读取图片与视频)Read a UTF-8 or UTF-16 text file, an image, or a video file from the active environment's filesystem, or a kimi-file:// attachment of this session.,附件段移除ReadMediaFile引用(引导所有会话的模型统一用Read读取文本、图片和视频)Read工具的会话(默认 profile、Plan 模式、Tower worker、自定义 agent)ReadTool.readMedia返回能力缺失错误约束)packages/agent-core-v2/src/agent/tools/os/read/read.md路径直读、分页与媒体说明Read、输出<line-number>\t<content>,无媒体说明Text output/Text results;新增- Image and video files are supported up to ${MAX_MEDIA_MEGABYTES}MB when the current model supports the corresponding input modality. After generating or editing media via commands or scripts, read the result back before continuing.Read工具的会话ReadTool.readMedia对分页参数、100MB 大小、模态能力与二进制 NUL 字节做硬性运行时校验packages/agent-core-v2/src/agent/media/image-compress.ts(buildImageCompressionCaption)ReadMediaFile搭配region查看原图路径局部ReadRead读取packages/agent-core-v2/docs/state-manifest.d.ts与@moonshot-ai/agent-core-v2内部导出'media.registeredKey': string | undefined(persist: false);packages/agent-core-v2/src/index.ts导出READ_MEDIA_FILE_TOOL_NAME、IMediaToolsRegistrar、cropImageForModel等符号'media.registeredKey'及上述已下线内部导出;公开 SDK@moonshot-ai/kimi-code-sdk(packages/node-sdk/src/index.ts)导出面保持不变(READ_IMAGE_BYTE_BUDGET、persistOriginalImage原样保留)@moonshot-ai/agent-core-v2内部包的工作区代码'media.registeredKey'从未落盘到wire.jsonl,新版本读旧会话与回滚旧版本读新会话均完全兼容ReadMediaFile;ACP 工具调用kind为'other'Read;ACP 工具调用kind归为'read';Web/Desktop(READ_MEDIA_TOOL_RE)与 TUI 在Read返回媒体内容时渲染媒体卡片/摘要,同时保留'ReadMediaFile'分支以兼容旧会话回放ReadMediaFile卡片渲染完整保留旧
ReadMediaFile路径功能迁移核对清单KIMI_IMAGE_READ_BYTE_BUDGET与KIMI_IMAGE_MAX_EDGE_PX:保留配置注入与packages/agent-core-v2/src/agent/media/image-compress.ts预算解析,由ReadTool.readMedia(readTool.ts)原样调用resolveReadImageByteBudget()与resolveMaxImageEdgePx()。MAX_MEDIA_BYTES = 100MB)与解码保护上限(MAX_IMAGE_DECODE_BYTES):迁入read.ts与ReadTool.readMedia,超限文案保持清晰说明。daemon-file://会话附件读取与本地/远程工作区路径校验:复用ReadTool既有的attachmentExecution、EnvironmentWorkspaceView、工作区边界检查与Read(path)审批规则匹配。image_compress(source: 'read_media')遥测:迁入ReadTool.readMedia,行为与原ReadMediaFileTool一致。ISessionMediaStore.put写入与AbortSignal取消透传:在ReadTool.readMedia中将signal透传给attachmentStore.put,确保中途取消(如大视频写入/上传)可及时中断。createVideoUploader与video_upload遥测:从删除的registerMediaTools.ts迁至packages/agent-core-v2/src/agent/media/videoUpload.ts,继续由mediaResolverService.ts调用。ReadMediaFile隐藏降级:保留在packages/agent-core-v2/src/agent/loop/mediaPolicy.ts(hideReadMediaFile)。受影响模块与验证结论
@moonshot-ai/agent-core-v2、@moonshot-ai/app-core、@moonshot-ai/kimi-code(TUI)、@moonshot-ai/acp-server(测试适配)、@moonshot-ai/klient(测试适配)、用户文档docs/{en,zh}。node:24-bookworm)环境核对:本地文件读取、POSIX/Windows 路径规则单元测试(read.test.ts)、TUI 虚拟终端流测试(含视频上传中途取消恢复)、旧会话恢复与 compaction 提醒重注入测试,以及真实released-2.6.3会话子进程冷恢复测试;Windows 环境待本 PR 的 CI 工作流进一步验证。pnpm lint、pnpm run check:duplication、agent-core-v2/apps/kimi-code/apps/desktop(含vue-tsc)/acp-server类型检查、媒体读取与压缩单测、旧会话恢复(含Readschema 刷新、ReadMediaFile过滤、legacy_read_media_merged一次性迁移提醒与跨模态切换提醒)测试、ACP / klient / kap-server 集成测试及released-2.6.3冷恢复测试均已通过。完整验证命令与测试文件清单
pnpm lint(macOS / Linux) — 通过(0 warnings, 0 errors)pnpm run check:duplication 7f71717094b8ee1c8ee0b9a3eeffe6f9ba1746d7— 通过pnpm exec tsc -p packages/agent-core-v2/tsconfig.json --noEmit— 通过pnpm exec vitest run --reporter=agent --maxWorkers=15 packages/agent-core-v2/test/wire/resume.test.ts packages/agent-core-v2/test/agent/toolSelect tests/scenarios/cold-recovery.test.ts(Linux) — 通过(5 files, 160 tests,含released-2.6.3真实旧版会话冷恢复;修复前对照新增的 2 条legacy_read_media_merged恢复提醒用例如期失败)Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.